/*
 * CategoryTreeInfoItem.java
 * business
 *
 * Created by SunDing on 2016/9/9.
 *
 * Copyright (c) 2016年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.listview.displaylistitem;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yidiandao.business.R;
import com.yidiandao.business.data.response.CategoryResponse;
import com.yidiandao.business.ui.searchabout.categorysearchgoods.CategorySearchGoodsActivity;
import com.yidiandao.business.ui.widget.listview.DisplayListItem;
import com.yidiandao.business.ui.widget.listview.viewholder.CategoryTreeInfoHolder;
import com.yidiandao.business.utils.ImageLoader;
import com.yidiandao.business.utils.UmengUtils;

import java.util.List;

/** 首页 分类 右边 分类类容 */
public class CategoryTreeInfoItem
        extends DisplayListItem<
        CategoryTreeInfoHolder, List<CategoryResponse.DataBean.CatListBean.Cat>> {

    public CategoryTreeInfoItem(List<CategoryResponse.DataBean.CatListBean.Cat> s) {
        super(s);
    }

    @Override
    public void onShow(final Context context, CategoryTreeInfoHolder holder) {

        LinearLayout[] ll = {holder.mLlCategory1, holder.mLlCategory2, holder.mLlCategory3};
        ImageView[] iv = {holder.mIvLogo1, holder.mIvLogo2, holder.mIvLogo3};
        TextView[] tv = {holder.mTvName1, holder.mTvName2, holder.mTvName3};

        holder.mLlCategory2.setVisibility(data.size() >= 2 ? View.VISIBLE : View.INVISIBLE);
        holder.mLlCategory3.setVisibility(data.size() == 3 ? View.VISIBLE : View.INVISIBLE);

        final String[] id = new String[data.size()];
        final String[] name = new String[data.size()];
        for (int i = 0; i < data.size(); i++) {
            id[i] = data.get(i).getCat_id();
            name[i] = data.get(i).getCat_name();
            tv[i].setText(name[i]);
            ImageLoader.loadImageFitXY(context, iv[i], data.get(i).getCat_img());
            final int finalI = i;
            ll[i].setOnClickListener(
                    new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            UmengUtils.onEvent(context, R.string.umeng_category_brand);
                            CategorySearchGoodsActivity.actionStart(
                                    (Activity) context, id[finalI], name[finalI]);
                        }
                    });
        }
    }

    @Override
    public String getDisplayItemTag() {
        return CategoryTreeInfoItem.class.getSimpleName();
    }

    @Override
    public Class<CategoryTreeInfoHolder> getViewHolderClazz() {
        return CategoryTreeInfoHolder.class;
    }
}
